from fastapi import status
from fastapi.responses import JSONResponse  # , ORJSONResponse
from pydantic import BaseModel
from typing import Union, Optional
from pydantic import BaseModel, Field


class PageParams(BaseModel):
    page: int = Field(default=1, title="页码", description="页码")
    size: int = Field(default=10, title="每页条数", description="每页条数")
    params: dict = Field(default=None, title="查询参数", description="查询参数")


class PageResult(BaseModel):
    page: int = Field(default=1, title="页码", description="页码")
    size: int = Field(default=10, title="每页条数", description="每页条数")
    total: int = Field(default=0, title="总数", description="总数")
    list: object = Field(default=None, title="页码", description="分页数据列表")


class ApiResult(BaseModel):
    code: int = Field(default=200, description="状态码")
    msg: str = Field(default="", description="错误描述")
    data: object = Field(default=None, description="数据")


class respJsonBase(BaseModel):
    code: int
    msg: str
    data: Union[dict, list]

#
# # 找不到路径
# ERROR_NOT_FOUND = ErrorBase(code=404, msg="api 路径错误")
# # 参数错误
# ERROR_PARAMETER_ERROR = ErrorBase(code=400, msg="参数错误")
#
# # 用户相关
# ERROR_USER_TOKEN_FAILURE = ErrorBase(code=5004, msg="未登录或登录过期")
# ERROR_USER_NOT_FOUND = ErrorBase(code=5004, msg="用户不存在")
# ERROR_USER_PASSWORD_ERROR = ErrorBase(code=5005, msg="密码错误")
# ERROR_USER_NOT_ACTIVATE = ErrorBase(code=5006, msg="用户账号尚未")
# ERROR_USER_ACCOUNT_EXISTS = ErrorBase(code=5007, msg="账号已存在")
# ERROR_USER_EMAIL_NOT_EXISTS = ErrorBase(code=5008, msg="邮箱不存在")
# ERROR_FORGET_PWD_TOKEN_ERROR = ErrorBase(code=5009, msg="重置密码链接错误或已过期")
# ERROR_USER_REGISTER_TOKEN_ERROR = ErrorBase(code=5031, msg="注册验证链接已过期或不存在")
# ERROR_USER_REGISTER_EXISTS = ErrorBase(code=5032, msg="注册失败，可能账号已存在。")
# ERROR_USER_REGISTER_ERROR = ErrorBase(code=5033, msg="注册失败，请重试。")
# ERROR_USER_REGISTER_TO_OFTEN = ErrorBase(code=5034, msg="提交注册太频繁，请稍后重试")
# ERROR_USER_EMAIL_EXISTS = ErrorBase(code=5011, msg="邮箱不可用")
# ERROR_USER_PHONE_EXISTS = ErrorBase(code=5012, msg="手机号码不可用")
# ERROR_USER_USERNAME_EXISTS = ErrorBase(code=5013, msg="用户名不可用")
# ERROR_USER_CAPTCHA_CODE_ERROR = ErrorBase(code=5021, msg="验证码错误")
# ERROR_USER_CAPTCHA_CODE_INVALID = ErrorBase(code=5022, msg="验证码已失效，请重试。")
# ERROR_USER_PREM_ADD_ERROR = ErrorBase(code=5031, msg="权限标识添加失败")
# ERROR_USER_PREM_ERROR = ErrorBase(code=5403, msg="权限不足")
#
#
# def respSuccessJson(data: Union[list, dict, str] = None, msg: str = "Success"):
#     """ 接口成功返回 """
#     return JSONResponse(
#         status_code=status.HTTP_200_OK,
#         content={
#             'code': 0,
#             'msg': msg,
#             'data': data or {}
#         }
#     )
#
#
# def respErrorJson(error: ErrorBase, *, msg: Optional[str] = None, msg_append: str = "",
#                   data: Union[list, dict, str] = None, status_code: int = status.HTTP_200_OK):
#     """ 错误接口返回 """
#     return JSONResponse(
#         status_code=status_code,
#         content={
#             'code': error.code,
#             'msg': (msg or error.msg) + msg_append,
#             'data': data or {}
#         }
#     )
